//获取应用实例
import network from '../../utils/network.js';
const app = getApp()

Page({
 
    /**
     * 页面的初始数据
     */
    data: {
      isHiddenToast: true,
      page: 1,
      rows: 10,
      total: 0,
      hasMoreData: true,
      Inx: 0,
      list: [],
      userInfo: [],
    },
 
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function () { 
      var that = this;
      wx.getStorage({
        key: 'user',
        success: function (res) {
          console.log(res);
          that.setData({
            userInfo: res.data,
          });
          that.onGetShopList("加载数据列表");
        }
      });
    },


    onGetShopList: function (message) {
      var that = this;
      var userInfo = that.data.userInfo;
      var latituded; var longituded;
      wx.getLocation({
        type: 'wgs84',
        success: function (re) {
          var data = {
            member_id: that.data.userInfo.id,
            latitude: re.latitude,
            longitude: re.longitude,
            rows:that.data.rows,
            page: that.data.page,
          };
          network.requestLoading('http://jbc.com/api/Member/shop_list', data, message, function (res) {
            var contentlistTem = that.data.list; 
            if (res.code > 0) {
              if (contentlistTem.length < res.data.total) {
                that.setData({
                  page: that.data.page + 1,
                  list: res.data.list,
                });
              } else {
                that.setData({
                  hasMoreData: false
                });
              }
            } else {
              // wx.showToast({
              //   title: res.msg,
              // });
            }
          }, function (res) {
            wx.showToast({
              title: '加载数据失败',
            })

          })
        }
      });
    },

    /*
    *进入门店
    */
    onGoShop: function (e) {
      var id = e.currentTarget.dataset.id
      wx.navigateTo({
        url: '/home/stores/stores?id=' + id,
      });
    },
    /*
* 导航跳转
*/
    goLocation: function (e) {
      var addr = e.currentTarget.dataset.addr
      wx.navigateTo({
        url: '/view/location/location?addr=' + addr,
      });
    },

    /**
* 页面相关事件处理函数--监听用户下拉动作
*/
    onPullDownRefresh: function () {
      this.data.page = 1;
      this.onGetShopList('正在刷新数据')
      console.log("下拉加载更多")
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
      console.log("下滑加载更多")
      if (this.data.hasMoreData) {
        this.onGetShopList('加载更多数据');
      } else {
        console.log("没有更多的数据")
        wx.showToast({
          title: '没有更多数据',
        })
      }
    },


 
})
